package com.lorizz.picpub.web;

import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.lorizz.upm.np.UserProfileNP;

public class SigninInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		UserProfileNP userProfileNP = (UserProfileNP) request.getSession().getAttribute(Constants.SESSION_USERPROFILE);
		if (userProfileNP != null)
			return true;
		String path = request.getRequestURI();
		response.sendRedirect("/signin?path=" + URLEncoder.encode(path, "utf-8"));
		return false;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {

	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {

	}

}
